<html>
    <head>
        <meta charset="utf-8">
        <title>地图移动结束事件</title>
        <!-- leaflet的css样式 -->
        <link rel="stylesheet" href="../lib/leaflet.css" />
        <!-- leaflet的js库 -->
        <script type="text/javascript" src="../lib/leaflet-src.js"></script>
        <!-- 地图容器样式 -->
        <style>
            #mapDiv{
                width: 100%;
                height: 100%;
            }
        </style>

        <script type="text/javascript">
            var map = null; 

            function init(){

                //1.创建map对象
                map = L.map("mapDiv", { 
                    layers: [
                        L.tileLayer( 'http://{s}.tile.osm.org/{z}/{x}/{y}.png')
                    ],
                    center: [39.90, 116.39],
                    zoom: 9
                });

                //2. 绑定moveend事件
                map.on('moveend', function(ev) {
                    //在文本框中地图中心点
                    var center = map.getCenter();
                    document.getElementById("X").value = center.lng;
                    document.getElementById("Y").value = center.lat;
                });

            }
        </script>
            
    </head>
    <body onload="init()">
        <span>地图中心点：</span>
        <input id="X" type="text" value="0.0" size='20'>
        -
        <input id="Y" type="text" value="0.0" size='20'>
        <!--地图的容器-->
        <div id="mapDiv"></div>
    </body>
</html>



